﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Idte.Common.Process
{
    public class ExecutionEngine : IExecutionEngine
    {
        IControlFlow control;
        
        public ExecutionEngine(IControlFlow control, IExecutionContext context)
        {
            this.control = control;
            this.Context = context;
        }

        public IExecutionContext Context { get; set; }
        public void Run(IExecutionContext context)
        {
            if (control.IsStepWise)
            {
                if (control.MoveNext(context))
                    context = control.Current.Create().Execute(context);
            }
            else
            {
                while (control.MoveNext(context))
                {
                    context = control.Current.Create().Execute(context);
                }
            }
        }
    }
}
